<template>
  <div class="algo-score-container">
    <!-- 算法名称 -->
    <!-- <div v-if="algorithm" class="algo-name">已选算法：{{ algorithm }}</div> -->
    <!-- 占位 -->
    <!-- <div v-else class="placeholder">暂无算法</div> -->

    <!-- 大分数 -->
    <div v-if="activateIndex == 1" class="score">{{ formattedScore }}</div>
    <div v-if="activateIndex == 2">
      <!-- 预览图 -->
      <img v-if="imageUrl" :src="imageUrl" class="image-preview" alt="预览图片" />
    </div>
  </div>
</template>

<script>
export default {
  name: 'AlgorithmScoreDisplay',
  props: {
    algorithm: {
      type: String,
      default: ''
    },
    score: {
      // 接收数字或字符串（如果外部传 '--' 也能显示）
      type: [Number, String],
      default: '--'
    },
    activateIndex: {
      type: Number,
      default: 1
    },
    imageUrl: {
      type: String,
      default: ''
    }
  },
  computed: {
    formattedScore() {
      // 如果是数字就保留一位小数，否则直接显示原始值
      return typeof this.score === 'number'
        ? this.score.toFixed(1)
        : this.score;
    }
  }
}
</script>

<style lang="scss" scoped>
.image-preview {
  width: 100%;
  height: 80%;
  object-fit: cover;
  display: block;
}

.algo-score-container {
  /* 容器基础 */
  padding: 1rem;
  width: 100%;
  height: 100%;
  // background: #0d0f17;
  // border: 2px solid #00eaff;
  // border-radius: 8px;
  box-shadow: 0 0 20px rgba(0, 234, 255, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  // overflow: visible;
}

/* 算法名称 */
.algo-name {
  font-size: 1.6rem;
  color: #8fdfff;
  margin-bottom: 1rem;
  position: relative;
  z-index: 2;
  /* 确保在分数发光层之上 */
}

/* 无算法时的占位 */
.placeholder {
  font-size: 1.2rem;
  color: #666;
  margin-bottom: 2rem;
}

/* 大分数 */
.score {
  line-height: 80%;
  font-size: 6rem;
  font-weight: bold;
  background: linear-gradient(90deg, #00eaff, #0066ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  position: relative;
  z-index: 999;
  animation: glow 1.5s ease-in-out infinite alternate;
  text-shadow: 0 0 10px rgba(0, 234, 255, 0.6),
    0 0 20px rgba(0, 234, 255, 0.4);
}

/* 发光动画 */
@keyframes glow {
  to {
    text-shadow: 0 0 20px rgba(0, 234, 255, 0.8),
      0 0 30px rgba(0, 234, 255, 0.6);
  }
}
</style>
